package com.powernode.money.web.interceptor;

import com.powernode.money.constant.Constants;
import com.powernode.money.model.User;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User user = (User) request.getSession().getAttribute(Constants.SESSION_USER);
        if (user !=null){
            return true;
        }else {
            response.sendRedirect(request.getContextPath() + "/loan/page/login");
            return false;
        }


    }
}
